home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 September / macformat-004.iso / Shareware City / Graphics / VideoToolbox ƒ / VideoToolboxSources / MacMemory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-07  |  940 b   |  31 lines  |  [TEXT/KAHL]

  1. /* 
  2. MacMemory.c
  3.  
  4. This is meant to be used in association with MacMemory.h, which redefines the
  5. Standard C memory allocation functions to be implemented directly as calls to
  6. the Macintosh Memory Manager. So don't write programs that explicitly call
  7. "MacRealloc". This is for portable C programs that call "realloc", but which
  8. will be compiled to use MacRealloc instead, for best performance on the Mac.
  9.  
  10. You use MacMemory.h by adding the line "#include <MacMemory.h>" either to your THINK C 
  11. project prefix or to some header file that you include in all your files.
  12. */
  13. #include <MacMemory.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <Memory.h>
  17.  
  18. void *MacRealloc(void *oldPtr,size_t size)
  19. {
  20.     void *newPtr;
  21.     
  22.     if(oldPtr==NULL)return NewPtr(size);
  23.     SetPtrSize(oldPtr,size);
  24.     if(MemError()){
  25.         newPtr=NewPtr(size);
  26.         if(newPtr==NULL)return newPtr;
  27.         memcpy(newPtr,oldPtr,size);
  28.         DisposPtr(oldPtr);
  29.     }else newPtr=oldPtr;
  30.     return newPtr;
  31. }